//
//  UserBaseVC.m
//  licai
//
//  Created by Rajon on 15/12/2.
//  Copyright © 2015年 Boye. All rights reserved.
//

#import "UserBaseVC.h"

@interface UserBaseVC ()

@end

@implementation UserBaseVC

-(void) dealloc{
    
    // 输入框内容改变通知
    [_NOTIFICATION_CENTER removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // 创建_scrollView
    [self _createScrollView];
    // 创建导航栏左边返回按钮
    [self createLeftBarButtonItemWithImagename:nil];
    
    // 输入框内容改变通知
    [_NOTIFICATION_CENTER addObserver:self selector:@selector(allTextFieldEndEditing) name:UITextFieldTextDidChangeNotification object:nil];
}

-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    
    if ([SVProgressHUD isVisible]) {
        [SVProgressHUD dismissAfterDelay:2];
    }
    
    
}
#pragma mark - 创建_scrollView
// 创建_scrollView
- (void)_createScrollView {
    
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
}

#pragma mark - 键盘弹出时执行，使编辑栏随键盘上升变成可以滑动（覆写父类方法）
- (void)keyboardFrameChange:(NSNotification *)notification {
    [super keyboardFrameChange:notification];
    //获取键盘的frame
    NSValue *boundsValue = [notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect frame = [boundsValue CGRectValue];
    //键盘y值
    CGFloat y = frame.origin.y;
    //调整_scrollView可滑动范围
    NSArray *subviews = _scrollView.subviews;
    UIView *lastSubview = nil;
    for (NSInteger i = subviews.count-1; i >= 0; i --) {
        if ([subviews[i] isKindOfClass:[UIButton class]]) {
            lastSubview = subviews[i];
            break;
        }
    }
    if (lastSubview.bottom > y - 64 - 30) { // 被遮挡了 30是完成视图的高度
        CGFloat distance = lastSubview.bottom - y;
        _scrollView.contentSize = CGSizeMake(_scrollView.width, _scrollView.height + distance + 20 + 30 +  - (self.navigationController.navigationBar.translucent ? 40 : 0));
    } else { // 未被遮挡
        _scrollView.contentSize = CGSizeZero;
    }
}

- (void)allTextFieldEndEditing {
    
}
@end
